using Coding4Fun.Phone.Controls.Primitives;
using Coding4Fun.Phone.Controls.Toolkit.Common;
using System;
using System.Globalization;
using System.Windows;
namespace Coding4Fun.Phone.Controls.Toolkit
{
	public class TimeSpanPicker : ValuePickerBase<TimeSpan>
	{
		public static readonly DependencyProperty MaxProperty = DependencyProperty.Register("Max", typeof(TimeSpan), typeof(ValuePickerBase<TimeSpan>), null);
		public static readonly DependencyProperty StepProperty = DependencyProperty.Register("Step", typeof(TimeSpan), typeof(ValuePickerBase<TimeSpan>), null);
		public TimeSpan Max
		{
			get
			{
				return (TimeSpan)base.GetValue(TimeSpanPicker.MaxProperty);
			}
			set
			{
				base.SetValue(TimeSpanPicker.MaxProperty, value);
			}
		}
		public TimeSpan Step
		{
			get
			{
				return (TimeSpan)base.GetValue(TimeSpanPicker.StepProperty);
			}
			set
			{
				base.SetValue(TimeSpanPicker.StepProperty, value);
			}
		}
		public TimeSpanPicker()
		{
			base.set_DefaultStyleKey(typeof(TimeSpanPicker));
			base.Value = new TimeSpan?(TimeSpan.FromMinutes(30.0));
			this.Max = TimeSpan.FromHours(24.0);
			this.Step = TimeSpan.FromSeconds(1.0);
			base.DialogTitle = ValuePickerResources.TimeSpanPickerTitle;
		}
		protected internal override void UpdateValueString()
		{
			if (base.Value.get_HasValue())
			{
				TimeSpan value = base.Value.get_Value();
				if (this.Max > TimeSpan.Zero && value > this.Max)
				{
					base.Value = new TimeSpan?(this.Max);
					return;
				}
				if (!string.IsNullOrEmpty(base.ValueStringFormat))
				{
					base.ValueString = TimeSpanFormat.Format(value, base.ValueStringFormat);
					return;
				}
			}
			base.ValueString = string.Format(CultureInfo.get_CurrentCulture(), base.ValueStringFormat ?? this.ValueStringFormatFallback, new object[]
			{
				base.Value
			});
		}
		protected override void NavigateToNewPage(object page)
		{
			ITimeSpanPickerPage<TimeSpan> timeSpanPickerPage = page as ITimeSpanPickerPage<TimeSpan>;
			if (timeSpanPickerPage != null)
			{
				timeSpanPickerPage.Max = this.Max;
				timeSpanPickerPage.IncrementStep = this.Step;
			}
			base.NavigateToNewPage(page);
		}
	}
}
